const app = getApp();
Page({
  data: {
    btn_login: "登录",
    userName: "",
    pwd: "",
    userType: 0,
    wagonerInfo:null
  },//获取用户输入的用户名
  userNameInput: function (e) {
    this.setData({
      userName: e.detail.value
    })
  },//获取用户输入的密码
  passWdInput: function (e) {
    this.setData({
      pwd: e.detail.value
    })
  },
  login: function () {
    var that = this;
    console.log(that.data.userName);
    // wx.redirectTo()
    wx.request({
      url:   getApp().globalData.server_support + "/collect-scrap/wagonerLogin",
      data: '{"userName":"' + that.data.userName + '","userPassword":"' + that.data.pwd + '","userType":"1"}',
      method:'POST',
      header:{
        'token': getApp().globalData.token
      },
      success:function(res){
        console.log("登陆成功数据：");
        console.log(res.data);
        if(res.data.success){
          getApp().globalData.userType = res.data.data.userType
          getApp().globalData.token = res.data.data.token
          that.setData({
            wagonerInfo: res.data.data
          })
          wx.switchTab ({
            url: '../../pages/orderview/orderview'
          });
        }else{
          that.setData({
            btn_login: '登陆',
            error_msg: res.data.message
          });
        }
       
      },
      fail:function(res){
        console.log(res);
        that.setData({
          btn_login: '登陆失败',
          error_msg:res.data.message
        })
      }
    })
  },
  onShow: function () {
    wx.setNavigationBarTitle({
      title: '个人中心'
    })
    console.log("个人中心userType：" + app.globalData.userType);
    this.setData({
      userType: app.globalData.userType
    })
    wx.setNavigationBarTitle({
      title: '三轮兄弟'
    })
  },
  loginOut:function(){
    console.log("开始登出")
    app.globalData.userType = 0;
    app.globalData.token = null;
    wx.switchTab({
      url: '../../pages/order/order',
    })
    console.log("结束登出")
  }
})